/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-05 11:35:18
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-05 11:46:58
 * @Description: file content
 */

#include "apue.h"
#include <sys/wait.h>

char *env_init[] = {"USER=unknown", "PATH=/tmp", NULL};

int main()
{
    pid_t pid;

    // 第一个进程
    if ((pid = fork()) < 0)
    {
        err_sys("fork error");
    }
    else if (0 == pid)
    {
        if (execle("ls", "ls", "myarg1", "MY ARG2", (char*)0, env_init) < 0)
        {
            err_sys("execle error");
        }
    }

    if (waitpid(pid, NULL, 0) < 0)
    {
        err_sys("waitpid error");
    }

    // 第二个进程
    if ((pid = fork()) < 0)
    {
        err_sys("fork error");
    }
    else if (0 == pid)
    {
        if (execlp("ls", "ls", "myarg1", (char*)0) < 0)
        {
            err_sys("execlp error");
        }
    }
}
